import MsgHints from "../common/MsgHints";
import MyComponent from "../common/MyComponent";
import { GameConst } from "../constant/GameConst";
import Core from "../Core";
import { GuideManager } from "../GuideSystem/GuideManager";

const { ccclass, property } = cc._decorator;

@ccclass
export default class Login extends MyComponent {
  constructor() {
    super();
    this.layer = GameConst.WIN_LAYER.SCENE;
    this.winType = GameConst.WIN_TYPE.FULL;
  }

  private GuideView: cc.Node = null;
  private node_ui: cc.Node = null;
  protected async onLoad() {
    this.preloadWin();
  }

  protected async start() {
    // 初始化引导系统（只需一次，正式项目，可以迁移至App.ts中）
    if (!GuideManager.instance["view"]) {
      await GuideManager.instance.init(
        this.GuideView.getComponent("GuideView")
      );
      // 检查是否需要引导
      GuideManager.instance.startGuideIfNeeded("menu_guide");
    }
  }

  protected onEnable(): void {
    Core.windowManager.register(this.node_ui);
  }

  //预加载窗口实例
  async preloadWin() {
    //适龄提示界面
    await Core.windowManager.preloadWindows([
      { info: GameConst.AgeTipsWin },
      { info: GameConst.TestListView },
    ]);
  }

  //===================按钮回调===================
  protected onClickBtnAgeTips() {
    Core.windowManager.open(GameConst.AgeTipsWin, null, false);
  }
  protected onClickBtnTestWin() {
    Core.windowManager.open(GameConst.TestListView, null, false);
  }
  protected onClickBtnTestHint() {
    MsgHints.show("测试提示");
  }
  protected onClickBtnTestStart() {
    cc.director.loadScene("gameScene");
  }

  protected onClickBtnMenuItem1() {
    Core.windowManager.open(GameConst.TestWinTwo, null, false);
  }
  protected onClickBtnMenuItem2() {
    Core.windowManager.open(GameConst.TestWinTwo, null, false);
  }
  protected onClickBtnMenuItem3() {
    Core.windowManager.open(GameConst.TestWinTwo, null, false);
  }
  protected onClickBtnMenuItem4() {
    Core.windowManager.open(GameConst.TestWinTwo, null, false);
  }
}
